package com.yanqu.road.server.logic.activity.condition.celebration;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.celebration.CelebrationMgr;

import java.math.BigInteger;

/**
 * @Description
 * @Author cwq
 * @Data 2021/7/14 15:51
 */
public class CelebrationActivityFestiveValueCondition extends BaseActivityCondition {

    public CelebrationActivityFestiveValueCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.CelebrationActivityFestiveCrossTotalValue.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.CelebrationActivityFestiveCrossTotalValue.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        //是否当前活动
        if(CelebrationMgr.getActivityInfo().getActivityId() != activityInfo.getActivityId()){
            return;
        }
        long totalLv = (long)object;
        BigInteger lv = BigInteger.valueOf(totalLv);
        if(lv.compareTo(getValue()) > 0){
            setValue(BigInteger.valueOf(totalLv));
        }
    }

}
